#ifndef OPERATELOG_H
#define OPERATELOG_H

#include "BaseEntity.h"



class OperateLog : public BaseEntity{
public:
    qlonglong operId;
    QString title;
    int businessType;
    QVector<int> businessTypes;
    QString method;
    QString requestMethod;
    int operatorType;
    QString operName;
    QString deptName;
    QString operUrl;
    QString operIp;
    QString operLocation;
    QString operParam;
    QString jsonResult;
    int status;
    QString errorMsg;
    QString operTime;

    QJsonObject toJson() const {
        QJsonObject object;
        object["operId"] = QJsonValue::fromVariant(operId);
        object["title"] = title;
        object["businessType"] = businessType;
        object["method"] = method;
        object["requestMethod"] = requestMethod;
        object["operatorType"] = operatorType;
        object["operName"] = operName;
        object["deptName"] = deptName;
        object["operUrl"] = operUrl;
        object["operIp"] = operIp;
        object["operLocation"] = operLocation;
        object["operParam"] = operParam;
        object["jsonResult"] = jsonResult;
        object["status"] = status;
        object["errorMsg"] = errorMsg;
        object["operTime"] = operTime;
        // Assuming businessTypes is an array of ints
        QJsonArray businessTypesArray;
        for (int i = 0; i < businessTypes.size(); i++) {
            businessTypesArray.append(businessTypes[i]);
        }
        object["businessTypes"] = businessTypesArray;
        object["searchValue"] = searchValue;
        object["createBy"] = createBy;
        object["createTime"] = createTime;
        object["updateBy"] = updateBy;
        object["updateTime"] = updateTime;
        object["remark"] = remark;
        return object;
    }

    static OperateLog toOperateLog(const QJsonObject& obj) {
        OperateLog operateLog;
        operateLog.operId = obj["operId"].toVariant().toLongLong();
        operateLog.title = obj["title"].toString();
        operateLog.businessType = obj["businessType"].toInt();
        operateLog.method = obj["method"].toString();
        operateLog.requestMethod = obj["requestMethod"].toString();
        operateLog.operatorType = obj["operatorType"].toInt();
        operateLog.operName = obj["operName"].toString();
        operateLog.deptName = obj["deptName"].toString();
        operateLog.operUrl = obj["operUrl"].toString();
        operateLog.operIp = obj["operIp"].toString();
        operateLog.operLocation = obj["operLocation"].toString();
        operateLog.operParam = obj["operParam"].toString();
        operateLog.jsonResult = obj["jsonResult"].toString();
        operateLog.status = obj["status"].toInt();
        operateLog.errorMsg = obj["errorMsg"].toString();
        operateLog.operTime = obj["operTime"].toString();
        // Assuming businessTypes is an array of ints
        QJsonArray businessTypesArray = obj["businessTypes"].toArray();
        for (int i = 0; i < businessTypesArray.size(); i++) {
            operateLog.businessTypes[i] = businessTypesArray[i].toInt();
        }
        operateLog.searchValue = obj["searchValue"].toString();
        operateLog.createBy = obj["createBy"].toString();
        operateLog.createTime = obj["createTime"].toString();
        operateLog.updateBy = obj["updateBy"].toString();
        operateLog.updateTime = obj["updateTime"].toString();
        operateLog.remark = obj["remark"].toString();
        return operateLog;
    }
};

#endif // OPERATELOG_H
